/*
 * @Author: Yang Zhang
 * @Date: 2021-12-04 00:24:18
 * @LastEditors: Yang Zhang
 * @LastEditTime: 2021-12-29 10:35:32
 * @Description: 
 */

import { request } from "../utils/request"
import { IAddtag, IStoreproitem } from "./types"

const api = {
  getByLevel: '/store/field',
  canChoosePro: '/store/goods/canChoose',
  storeProlist: '/store/goods/getByStore',
  addProduct: '/store/goods/choose',
  getBystore: '/store/goods/getByStore',
  allTags: '/store/goods/tag',
  addAtag: '/store/goods/tag/create',
  upPro: '/store/goods/up',
  underPro: '/store/goods/under',
  getByid: '/store/goods/get',
  upBystore: '/store/goods/upByStore',
  underBystore: '/store/goods/downByStore',
  chooseTag: '/store/goods/tag/chooseTag/',
  getTraces: '/store/orders/getTraces/',
  getProtags: '/store/goods/tag/getTagByStoreGoodsId/',
  deleteRealtag: '/store/goods/tag/removeRelation/',
  delStoregoods: '/store/goods/deleteStoreGoods',
  pronavlist: '/store/goods/category/getByStoreField',
  returnlevel: '/store/goods/category/getByLevel'
}


export const getProductlistnav = () => {
  return request({
    url: api.returnlevel,
    method: 'get',
    params: {
      level: 0
    }
  })
}

export const getProductnavList = () => {
  return request({
    url: api.pronavlist,
    method: 'get'
  })
}

/**
 * @description 删除标签
 * @param
 * @returns 
 */
export const delTagrel = (storeid: any, id: any) => {
  return request({
    url: api.deleteRealtag + storeid + '/' + id,
    method: 'delete'
  })
}

/**
 * @description:按级别获取商品类目
 */
export const getNavlist = (num: Number) => {
  return request({
    url: api.getByLevel,
    method: 'get',
  })
}

/** 
 * @description 分页获取可选择商品列表 分 类id传入到categoryPath字段
 */
export const canIchoose = (id: any, page: Number) => {
  return request({
    url: api.canChoosePro,
    method: 'get',
    params: { categoryPath: id, pageSize: 8, pageNumber: page }
  })
}

/**
 * @description:我的店铺商品列表
 */
export const storeProlist = (id: any) => {
  return request({
    url: api.storeProlist,
    method: 'get',
    params: { storeId: id }
  })
}

/**
 * @description:添加产品
 */
export const addProduct = (data: any) => {
  return request({
    url: api.addProduct,
    method: 'post',
    data: data,
    formData: true
  })
}

/**
 * @description 我的店铺商品列表
 */
export const getProlstbystore = (params: IStoreproitem) => {
  return request({
    url: api.getBystore,
    method: 'get',
    params: params
  })
}

/**
 * @description: 获取店铺所有商品标签
 */
export const getAllstoretags = () => {
  return request({
    url: api.allTags,
    method: 'get',
  })
}

/**
 * @description 添加一个店铺商品标签
 */
export const addAstoretag = (name: string) => {
  return request({
    url: api.addAtag,
    method: 'post',
    data: {
      tagName: name
    },
    formData: true
  })
}

/**
 * @description 上架产品
 */
export const upProduct = (arr: string[]) => {
  return request({
    url: api.upPro,
    method: 'put',
    data: {
      goodsId: arr
    },
    formData: true
  })
}
/**
 * @description 下架产品
 */
export const underProduct = (arr: string[]) => {
  return request({
    url: api.underPro,
    method: 'put',
    data: {
      goodsId: arr
    },
    formData: true
  })
}

export const getDetailByid = (id: string) => {
  return request({
    url: api.getByid + '/' + id,
    method: 'get'
  })
}

/**
 * @description:批量上架店铺商品
 */
export const upsomeBystore = (data: string[]) => {
  return request({
    url: api.upBystore,
    method: 'post',
    data: {
      ids: data.join(',')
    },
    formData: true
  })
}
/**
 * @description:批量上架店铺商品
 */
export const undersomeBystore = (data: string[]) => {
  return request({
    url: api.underBystore,
    method: 'post',
    data: {
      ids: data.join(',')
    },
    formData: true
  })
}

export const delProductitems = (data: string[]) => {
  return request({
    url: api.delStoregoods,
    method: 'put',
    data: {
      storeGoodsId: data.join(',')
    },
    formData: true
  })
}

/**
 * @description 给商品选择店铺标签
 */
export const addTagtoPro = (data: IAddtag) => {
  return request({
    url: api.chooseTag + data.storeGoodsId,
    method: 'post',
    data: {
      ids: data.ids.join(',')
    },
    formData: true
  })
}


/**
 * @description : 获取物流详情
 */
export const getDeliverdt = (sn: any) => {
  return request({
    url: api.getTraces + sn,
    method: 'get'
  })
}

/**
 * @description 获取商品标签集合
 */
export const getProtagsarr = (id: any) => {
  return request({
    url: api.getProtags + id,
    method: 'get'
  })
}